package com.nbgroup.controller;

import com.nbgroup.annotation.HttpMethod;
import com.nbgroup.pojo.common.PageResult;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.PageOperLogDto;
import com.nbgroup.pojo.vo.OperLogVo;
import com.nbgroup.service.OperlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.List;


/**
 * 系统日志接口
 */
@RestController
@Slf4j
@Api(tags = "系统日志接口")
public class OperlogController {
    @Autowired
    private OperlogService operlogService;

    @HttpMethod("GET")
    @GetMapping("/monitor/operlog/list")
    @ApiOperation("系统日志分页查询")
    public PageResult list(PageOperLogDto dto) {
         return operlogService.list(dto);
    }

    /**
     * 查询没有接口
     * 导出是什么啊 跳个json
     */

    @HttpMethod("DELETE")
    @DeleteMapping("/monitor/operlog/{ids}")
    @ApiOperation("删除日志")
    public Result delete(@PathVariable List<Integer> ids) {
        operlogService.delete(ids);
        return Result.success();
    }

    @HttpMethod("DELETE")
    @DeleteMapping("/monitor/operlog/clean")
    @ApiOperation("清空日志")
    public Result clean() {
        operlogService.clean();
        return Result.success();
    }


    /**
     * 导不来 路径不给选择id 有可以 选想导出的数据
     * @param ids
     * @return
     * @throws IOException
     */
    @HttpMethod("GET")
    @GetMapping("/monitor/operlog/export")
    @ApiOperation("导出日志")
    public Result export(@RequestParam List<Integer> ids) throws IOException {
        operlogService.export(ids);
        return Result.success();
    }
}
